package withdraw

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/assets-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/assets-api/internal/types"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"
	"github.com/zeromicro/go-zero/core/logx"
)

type WithdrawBankListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 用户提现页面--银行列表
func NewWithdrawBankListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WithdrawBankListLogic {
	return &WithdrawBankListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *WithdrawBankListLogic) WithdrawBankList(req *types.WithdrawBankListReq) (resp *types.WithdrawBankListRes, err error) {
	// todo: add your logic here and delete this line
	rpc_req := &rpc.GetWithDrawBankRequest{
		Status: int32(rpc.WithdrawStatus_Open),
	}

	// 发送请求
	rpc_resp, err := l.svcCtx.AssetsRpc.Config.BankListPage(l.ctx, rpc_req)
	if err != nil {
		logx.Errorf("Call ModifyVipLevelInfos error: %v", err)
		return nil, err
	}

	// 处理请求返回的结果
	// 解析、组合数据
	resp = &types.WithdrawBankListRes{}
	for _, d := range rpc_resp.Data {
		resp.Data = append(resp.Data, types.WithDrawBank{
			Id:       d.Id,
			BankName: d.BankName,
			BankCode: d.BankCode,
			BankLogo: d.BankLogo,
		})
	}
	return
}
